﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaccaratRally.DataKernel.Entity
{
    [BaccaratRally.DataKernel.Entity.SqlTableAttribute("Site")]
    public class Site : BaccaratRally.DataKernel.Entity.EntityBase
    {

        #region data fields
        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("SiteName", false, false, false, false)]
        public System.String SiteName { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("SiteUrl", false, false, false, false)]
        public System.String SiteUrl { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("ExtData", false, false, true, false)]
        public System.String ExtData { get; set; }

        #endregion

        internal override void ReBuildInstance(System.Data.SqlClient.SqlDataReader reader)
        {
            this.SiteName = GetReaderValue<System.String>(reader, "SiteName");
            this.SiteUrl = GetReaderValue<System.String>(reader, "SiteUrl");
            this.ExtData = GetReaderValue<System.String>(reader, "ExtData");
        }

        internal override System.Data.SqlClient.SqlParameter[] BuildInsertParamter()
        {
            BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection paramterList = new BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection();
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@SiteName", System.Data.SqlDbType.VarChar, 50));
            paramterList["@SiteName"].Value = this.SiteName;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@SiteUrl", System.Data.SqlDbType.VarChar, 500));
            paramterList["@SiteUrl"].Value = this.SiteUrl;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@ExtData", System.Data.SqlDbType.VarChar, 500));
            paramterList["@ExtData"].Value = this.ExtData;
            return paramterList.ToArray();
        }

        internal override System.Data.SqlClient.SqlParameter[] BuildUpdateParamter()
        {
            BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection paramterList = new BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection();
            return paramterList.ToArray();
        }

        internal override string GetInsertCommandText()
        {
            string sqlcmd = @"insert dbo.[Site]([SiteName],[SiteUrl],[ExtData])
                          values(@SiteName, @SiteUrl, @ExtData)
                          select * from dbo.[Site] where 1=1
                        ";
            return sqlcmd;
        }

        internal override string GetUpdateCommandText()
        {
            string sqlcmd = @"";
            return sqlcmd;
        }
    }

}
